﻿using Ndex.Core;
using System.Collections.Generic;
using System.Linq;

namespace System.ComponentModel.DataAnnotations
{
    public static class ListValidationResultExt
    {
        public static List<ValidationResult> Add(this List<ValidationResult> obj, string message, string memberNames)
        {
            if (!string.IsNullOrWhiteSpace(message))
                obj.Add(new ValidationResult(message, new string[] { memberNames }));
            return obj;
        }

        public static List<ValidationResult> Add(this List<ValidationResult> obj, string message, string memberNames, string value)
        {
            if(string.IsNullOrWhiteSpace(value))
                obj.Add(message,  memberNames );
            return obj;
        }

        public static List<ValidationResult> Add(this List<ValidationResult> obj, string message, string memberNames, bool value)
        {
            if (value)
                obj.Add(message,  memberNames );
            return obj;
        }

        public static List<ValidationResult> Add(this List<ValidationResult> obj, string message, string memberNames, long value)
        {
            if (value == 0)
                obj.Add(message,  memberNames);
            return obj;
        }

        public static List<ValidationResult> Add(this List<ValidationResult> obj, string message, string memberNames, long? value)
        {
            if (!value.HasValue)
                obj.Add(message, memberNames);
            return obj;
        }

        public static List<ValidationResult> AddRange(this List<ValidationResult> obj, List<ValidationModel> val)
        {
            obj.AddRange(val.Select(i => new ValidationResult(i.Message, i.MemberNames)));
            return obj;
        }
    }
}
